fn main(){
    //位运算
    //<< 左移	所有位向左移动指定位数，右位补0
    //>> 右移	所有位向右移动指定位数，带符号移动（正数补0，负数补1）
    // 无符号8位整数，二进制为00000010
    let a: i8 = -3; // 也可以写 let a: u8 = 0b_0000_0010;
    //let a: u8 = 3; // 也可以写 let a: u8 = 0b_0000_0010;

    // 二进制为00000011
    let b: u8 = 3;

    // {:08b}：左高右低输出二进制01，不足8位则高位补0
    println!("a value is {a:08b}");
    println!("b value is {b:08b}");
    println!("(a << b) value is {:08b}", a << b);
    println!("(a << b) value is {}", a << b);
    println!("(a >> b) value is {:08b}", a >> b);
    println!("(a >> b) value is {}", a >> b);

    let mut a = a;
    println!("注意这些计算符除了!之外都可以加上=进行赋值(因为!=要用来判断不等于)");
    a <<= b;
    println!("(a << b) value is {:08b}", a);
    println!("(a << b) value is {}", a);

    println!("x=3, y=4变成x=4, y=3.使用采用异或^");
    let x = 3_u8;
    let y = 4u8;
    println!("Begin: x = {x}, y= {y}");
    let x = x^y;
    let y = x^y;
    let x = x^y;
    println!("End: x = {x}, y= {y}");
    println!("3.1415926四舍五入{:0.3}",3.1415926);
    println!("13.14取整{}",3.1415926_f32.round());
}
